package ui;

import java.util.ArrayList;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

import util.Settings;

/**
 * Pause menu.
 * @author VincentLy
 */
public class PauseMenu extends BasicGameState{
	
	private ArrayList<CustomButton> buttons;
	private CustomButton commands;
	private CustomButton options;
	private CustomButton help;
	private CustomButton exit;
	private float ex,ey = -1;
	
	public PauseMenu(){
		super();
		buttons = new ArrayList<CustomButton>();
		commands = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + Settings.buttonY,"Command List",'m');	
		options = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + 2*Settings.buttonY,"Options",'o');	
		help = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + 3*Settings.buttonY,"Help",'h');	
		exit = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + 4*Settings.buttonY,"Exit",'e');	
		buttons.add(commands);
		buttons.add(options);
		buttons.add(help);	
		buttons.add(exit);
	}

	/**
	 * Initialization not needed yet.
	 * @author VincentLy
	 */
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {}

	/**
	 * Holds the options menu, move menu, and help menu.
	 * Checks for user advances.
	 * @author VincentLy
	 */
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		Input i = gc.getInput();
		if(i.isKeyPressed(Input.KEY_P))
			sbg.enterState(Settings.gameState);
		ex = i.getMouseX();
		ey = i.getMouseY();
		for(CustomButton b:buttons){
			if(b.contains(ex,ey)){
				b.setOn(true);	
				if(i.isMousePressed(Input.MOUSE_LEFT_BUTTON)){
					switch(b.name()){
					case 'o':
						sbg.enterState(Settings.oID);
						break;
					case 'h':
						sbg.enterState(Settings.hID);
						break;
					case 'm':
						sbg.enterState(Settings.mID);
						break;
					case 'e':
						sbg.enterState(Settings.smID);
						break;
					}
				}				
			}	
			else
				b.setOn(false);
		}	
	}
	
	/**
	 * Draws the menu components.
	 * @author VincentLy
	 */
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.setAntiAlias(true);
		g.setBackground(Color.black);
		g.drawImage(Settings.pause,0,0);
		g.setColor(Color.white);
		g.setLineWidth(1);
		for(CustomButton b:buttons){
			b.draw(g);	
			g.setLineWidth(1);
		}	
	}

	/**
	 * @return id
	 * @author VincentLy
	 */
	public int getID() {return Settings.pmID;}
}
